package com.aidex.biz.service.impl;

import com.aidex.biz.domain.Customer;
import com.aidex.biz.domain.CustomerTag;
import com.aidex.biz.mapper.CustomerTagMapper;
import com.aidex.biz.service.CustomerTagService;
import com.aidex.common.core.service.BaseServiceImpl;
import com.aidex.common.utils.NumberUtils;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 客户标签信息Service业务层处理
 *
 * @author sean
 * @email 2074844820@qq.com
 * @date 2025-04-01
 */
@Service
@Transactional(readOnly = true)
public class CustomerTagServiceImpl extends BaseServiceImpl<CustomerTagMapper, CustomerTag> implements CustomerTagService {
    private static final Logger log = LoggerFactory.getLogger(CustomerTagServiceImpl.class);

    /**
     * 获取单条数据
     *
     * @param customerTag 客户标签信息
     * @return 客户标签信息
     */
    @Override
    public CustomerTag get(CustomerTag customerTag) {
        CustomerTag dto = super.get(customerTag);
        return dto;
    }

    /**
     * 获取单条数据
     *
     * @param id 客户标签信息id
     * @return 客户标签信息
     */
    @Override
    public CustomerTag get(String id) {
        CustomerTag dto = super.get(id);
        return dto;
    }


    /**
     * 查询客户标签信息列表
     *
     * @param customerTag 客户标签信息
     * @return 客户标签信息
     */
    @Override

    public List<CustomerTag> findList(CustomerTag customerTag) {
        return super.findList(customerTag);
    }

    /**
     * 分页查询客户标签信息列表
     *
     * @param customerTag 客户标签信息
     * @return 客户标签信息
     */
    @Override

    public PageInfo<CustomerTag> findPage(CustomerTag customerTag) {
        return super.findPage(customerTag);
    }

    /**
     * 保存客户标签信息
     *
     * @param customerTag
     * @return 结果
     */
    @Override
    public boolean save(CustomerTag customerTag) {
        return super.save(customerTag);
    }


    /**
     * 删除客户标签信息信息
     *
     * @param customerTag
     * @return 结果
     */
    @Override
    public boolean remove(CustomerTag customerTag) {
        return super.remove(customerTag);
    }

    /**
     * 批量删除客户标签信息
     *
     * @param ids 需要删除的客户标签信息ID
     * @return 结果
     */
    @Transactional(readOnly = false)
    @Override
    public int deleteCustomerTagByIds(String[] ids) {
        return mapper.deleteCustomerTagByIds(ids);
    }

    /**
     * 获取最大编号
     *
     * @param customerTag 客户标签信息
     * @return 结果
     */
    @Override
    public int findMaxSort(CustomerTag customerTag) {
        return NumberUtils.nextOrder(mapper.findMaxSort(customerTag));
    }


    @Override
    public int deleteByCustomerId(String customerId) {
        return mapper.deleteByCustomerId(customerId);
    }

    @Override
    public boolean addBatch(Customer customer) {
        try {
            String customerId = customer.getId();
            List<CustomerTag> customerTagList = customer.getTagList();
            this.deleteByCustomerId(customerId);
            for (CustomerTag tag : customerTagList) {
                this.save(tag);
            }
        } catch (Exception e) {
            return false;
        }
        return true;
    }
}
